//
//  Config.h
//  CocoaAsyncSocket_TCP
//
//  Created by 孟遥 on 2017/4/20.
//  Copyright © 2017年 mengyao. All rights reserved.
//

#ifndef Config_h
#define Config_h


/****************************************************/
#define SCREEN_BOUNDS   [UIScreen mainScreen].bounds //屏幕bounds
#define SCREEN_WITDTH    [UIScreen mainScreen].bounds.size.width //屏宽
#define SCREEN_HEIGHT    [UIScreen mainScreen].bounds.size.height //屏高

// weakself,strongself
#define WeakSelf(type)  __weak typeof(type) weak##type = type; // weak
#define StrongSelf(type)  __strong typeof(type) type = weak##type; // strong
// 统一收起键盘
#define hideKeyboard [[[UIApplication sharedApplication] keyWindow] endEditing:YES]
/// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

///  View加边框
#define ViewBorder(View, BorderColor, BorderWidth )\
\
View.layer.borderColor = BorderColor.CGColor;\
View.layer.borderWidth = BorderWidth;

//frame
#define Frame(x,y,width,height)  CGRectMake(x, y, width, height)

//最大最小值
#define MaxX(frame) CGRectGetMaxX(frame)
#define MaxY(frame) CGRectGetMaxY(frame)
#define MinX(frame) CGRectGetMinX(frame)
#define MinY(frame) CGRectGetMinY(frame)
//宽度高度
#define Width(frame)    CGRectGetWidth(frame)
#define Height(frame)   CGRectGetHeight(frame)

#define NSStringFromFloat(floatValue)   [NSString stringWithFormat:@"%.2f",floatValue]
#define NSStringFromDouble(doubleValue)   [NSString stringWithFormat:@"%f",doubleValue]
#define NSStringFromInt(intValue)       [NSString stringWithFormat:@"%d",intValue]

//16进制颜色  eg:UICOLOR_RGB_Alpha(0xe6e6e6,1)
#define UICOLOR_RGB_Alpha(_color,_alpha) [UIColor colorWithRed:((_color>>16)&0xff)/255.0f green:((_color>>8)&0xff)/255.0f blue:(_color&0xff)/255.0f alpha:_alpha]
//加载本地图片
#define LoadImage(imageName) [UIImage imageNamed:imageName]
//加载不缓存图片
#define LoadImage_NotCache(imageName,imageType) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:imageName ofType:imageType]]
//设置字体
#define FontSet(fontSize)  [UIFont systemFontOfSize:fontSize]
//聊天缓存基本地址 (根据当前用户来创建缓存目录 , 每个登录用户创建单独资源文件夹,每个会话创建单独的文件夹 , 便于管理)
#define ChatCache_Path   [NSHomeDirectory() stringByAppendingString:[NSString stringWithFormat:@"/Library/Caches/ChatSource/%@",[Account account].myUserID]]

//手机判断
#define IS_IPHONE4      ([[UIScreen mainScreen] bounds].size.height == 480 ? YES : NO)
#define IS_IPHONE5      ([[UIScreen mainScreen] bounds].size.height == 568 ? YES : NO)
#define IS_IPHONE6      ([[UIScreen mainScreen] bounds].size.height == 667 ? YES : NO)
#define IS_IPHONE6PLUS  ([[UIScreen mainScreen] bounds].size.height == 736 ? YES : NO)

//打印
#ifdef DEBUG //调试状态
#define MYLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define MYLog(...)
#endif

#define showAlert(title_code) showDetailAlert(title_code,nil)
#define showErr(err_code) showAlert(LocalizedStringByInt(err_code))

#define showDetailAlert(title,detail) \
BasicAlertView *alertView = [BasicAlertView alertViewWithTitle:title \
subtitle:detail \
message:nil \
buttons:@[@"确定"] \
afterDismiss:^(int buttonIndex) {}];\
[alertView show]

//  单例
/*   --usage
 .h  singleton_interface(ClassName)
 .m  singleton_implementation(ClassName)
 eg. [Class shareInstance]
 */
#define singleton_interface(class) + (class *)shareInstance;

#define singleton_implementation(class)\
\
static class *_instance;\
+ (class *)shareInstance\
{\
if (_instance == nil) {\
_instance = [[self alloc] init];\
}\
return _instance;\
}\
\
+ (class *)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}




#endif /* Config_h */
